package com.example.demo.web;

import com.example.demo.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhy
 * @date 2019-10-16 10:28
 **/
@RestController
@RequestMapping("/search")
public class NurseDeptAction {
	private static final Logger log = LoggerFactory.getLogger(NurseDeptAction.class);

	@Resource
	@Qualifier("secondaryJdbcTemplate")
	protected JdbcTemplate oracleJdbcTemplate;

	/**
	 * 获取科室字典
	 */
	@GetMapping("/getBrjAction")
	public Object getBrjAction(){
		String sql = "select * from YMMOBILE.GY_BRJBXXK";
		log.info(sql);
		return ResponseUtil.ok(oracleJdbcTemplate.queryForList(sql));
	}

	@GetMapping("/getLabOrderAction")
	public Object getLabOrderAction(String PATIENTID,String PATIENTNAME){
		String sql = "select * from YMMOBILE.L_LABORDER";
		if (!StringUtils.isEmpty(PATIENTID)){
			sql=sql+" where PATIENTID='"+PATIENTID+"'";
		}
		if (!StringUtils.isEmpty(PATIENTID)){
			sql=sql+" and PATIENTNAME='"+PATIENTNAME+"'";
		}
		log.info(sql);
		return ResponseUtil.ok(oracleJdbcTemplate.queryForList(sql));
	}

	@GetMapping("/getResultAction")
	public Object getResultAction(String BARCODE,String PAT_NO){
		String sql = "select * from YMMOBILE.LIS_RESULT";
		if (!StringUtils.isEmpty(BARCODE)){
			sql=sql+" where BARCODE='"+BARCODE+"'";
		}
		if (!StringUtils.isEmpty(PAT_NO)){
			sql=sql+" and PAT_NO='"+PAT_NO+"'";
		}
		log.info(sql);
		return ResponseUtil.ok(oracleJdbcTemplate.queryForList(sql));
	}

}
